import Vue from "vue";
import Vuex from "vuex";
import {reqBannerList, reqCategoryList, reqFloorList} from "@/api";

Vue.use(Vuex);

// 数据
let state = {

    categoryList:[],   // 三级联动列表
    bannerList:[],    //轮播图
    floorList:[],     //楼层内容
};

// 写好逻辑后，提交给mutations处理修改数据
let actions = {
     reqCategoryList(context){
          reqCategoryList().then(value =>{
              context.commit('REQCATEGORYLIST',value.data.data)
          })
    },
   reqBannerList(context){
          reqBannerList().then(value =>{
              context.commit('REQBANNERLIST',value.data.data)
          })
   },
    reqFloorList(context) {
        reqFloorList().then(value => {
            context.commit('REQFLOORLIST', value.data.data)
        })
    }
};

// 只有mutations能够修改数据
let mutations = {
    REQCATEGORYLIST(state,value){

        value.length = 15;   //切割数据
        state.categoryList = value;
    },
    REQBANNERLIST(state,value){
        state.bannerList = value;
    },
    REQFLOORLIST(state,value){
        state.floorList = value;
    },
};

// 类似于计算属性
let getters = {};


export default {
    namespaced:true,
    state,
    mutations,
    actions,
    getters
}
